<?php
require_once '../includes/global.php';
if ($_SESSION['userinfo']['rcfg'] == "S") {
	$temp = Dgs('mod', "  parentid='1' and del !=1 and  ( t1 !='0' || t1 !='')  and lg like 'zh' ");

	$cls[0] = 'folder';
	$cls[1] = 'file';
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees['root'][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}
	$temp = Dgs('mod', "  parentid='6' and del !=1 and  ( t1 !='0' || t1 !='' )   and lg like 'zh' ");
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees['root2'][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}
	$temp = Dgs('mod', "  parentid='11' and del !=1 and  ( t1 !='0' || t1 !='' ) ");
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees['root3'][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}

	$temp = Dgs('mod', " parentid!='-1' && parentid!='1' && parentid!='5' && parentid!='11' and del !=1 and  ( t1 !='0' || t1 !='' ) and lg like 'zh'");
	$cls[0] = 'folder';
	$cls[1] = 'file';
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees[$value['parentid']][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}
}
else {

	$tempright = Dga('rcfg', " id ='".$_SESSION[userinfo][rightid]."' ");
	$tempright = json_decode($tempright['rcfg'], true);
	$rightkey = array_keys($tempright);
	//Jc($rightkey);
	$rar = array ();
	foreach ($rightkey as $rvalue) {
		$rstr = getparentidsorts($rvalue, 'mod');
		$tar = explode(',', $rstr);
		$rar = array_merge($rar, $tar);
	}
	$rar = array_unique($rar);
	$unkey = array_keys($rar, '-1');
	unset ($rar[$unkey[0]]);
	$tseslec = implode(',', $rar);
	$temp = Dgs('mod', "  parentid='1' and del !=1 and  ( t1 !='0' || t1 !='') and  id in(0,".$tseslec.")   and lg like 'zh' ");

	$cls[0] = 'folder';
	$cls[1] = 'file';
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees['root'][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}
	$temp = Dgs('mod', "  parentid='6' and del !=1 and  ( t1 !='0' || t1 !='' )  and    id in(0,".$tseslec.")    and lg like 'zh' ");
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees['root2'][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}


	$temp = Dgs('mod', "  parentid='11' and del !=1 and  ( t1 !='0' || t1 !='' )  and    id in(0,".$tseslec.")    and lg like 'zh'   ");
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees['root3'][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);
	}

	$temp = Dgs('mod', " parentid!='-1' && parentid!='1' && parentid!='5' && parentid!='11'   and lg like 'zh'  and del !=1 and  ( t1 !='0' || t1 !='' )   and    id in(0,".$tseslec.")  and lg like 'zh'");
	$cls[0] = 'folder';
	$cls[1] = 'file';
	foreach ($temp as $key=>$value) {
		if ($value['url'] != '') {
			$action = $value['url']."&mid=".$value[id]."&from=b";
		}
		else {
			$did = str_replace(',', "", $value['dcfg']);
			$action = 'mod/l.php?did='.$did."&mid=".$value[id]."&from=b";
		}
		if ($value['leaf'] == 0) {
			$leaf = false;
		}
		else {
			$leaf = true;
		}
		$trees[$value['parentid']][] = array ('id'=>$value[id], 'text'=>$value[title], 'leaf'=>$leaf, 'model'=>'user', 'cls'=>$cls[$value['leaf']], 'action'=>$action);

	}
}
require ('JSON.php');
$result = $trees[$_REQUEST['node']];
$json = new Services_JSON();
echo $json->encode($result);
?>
